/* eslint valid-jsdoc: "off" */

'use strict';

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
	/**
	 * built-in config
	 * @type {Egg.EggAppConfig}
	 **/
	const config = (exports = {});

	// use for cookie sign key, should change to your own and keep security
	config.keys = appInfo.name + '_1661857944518_7983';
	// add your middleware config here
	config.middleware = ['errHandler', 'auth'];
	// 鉴权白名单
	config.auth = {
		// ignore:
		match: [
			'/logout',
			'/upload',
			'/getSize',
			'/file',
			'/file/createDir',
			'/file/rename',
			'/file/delete',
			'/file/search',
			'/share/create',
			'/share/list',
			'/share/save',
			'/file/dir'
		]
	};
	// add your user config here
	const userConfig = {
		// myAppName: 'egg',
	};

	config.security = {
		// 关闭 csrf
		csrf: {
			enable: false
		}
		// 跨域白名单
		// domainWhiteList: [
		// 	'http://localhost:3000',
		// 	'http://127.0.0.1:5173',
		// 	'http://127.0.0.1:8080'
		// ]
	};
	// 允许跨域的方法
	config.cors = {
		origin: '*',
		allowMethods: 'GET, PUT, POST, DELETE, PATCH'
	};
	// egg-sequelize
	config.sequelize = {
		username: 'root',
		password: 'root',
		database: 'disk-server',
		host: '127.0.0.1',
		dialect: 'mysql',
		port: 3306,
		timezone: '+08:00',
		define: {
			// 取消数据表名复数
			freezeTableName: true,
			// 自动写入时间戳 created_at updated_at
			timestamps: true,
			// 字段生成软删除时间戳 deleted_at
			// paranoid: true,
			createdAt: 'created_time',
			updatedAt: 'updated_time',
			// deletedAt: 'deleted_tme',
			// 所有驼峰命名格式化
			underscored: true
		}
	};
	// app端url
	config.appUrl = 'http://localhost:8080/';
	// web端url
	config.webUrl = 'http://127.0.0.1:5173/';
	// 服务端域名
	config.serUrl = 'http://127.0.0.1:7001/';
	config.valparams = {
		locale: 'zh-cn',
		throwError: true // 主动抛出异常
	};
	config.crypto = {
		secret: 'gw@45ncashdaksh2!#@3nxjdas*_672' // 加密秘钥
	};
	// jwt
	config.jwt = {
		secret: 'gw@45ncashdaksh2!#@3nxjdas*_672' // token加密秘钥
	};

	// redis
	config.redis = {
		client: {
			port: 6379,
			host: '127.0.0.1',
			password: '',
			db: 0 // 使用0表
		}
	};

	config.fullQiniu = {
		default: {
			ak: '', // Access Key
			sk: '', // Secret Key
			useCdnDomain: true,
			isLog: true
		},
		app: true,
		agent: false,
		client: {
			zone: 'Zone_z0', // Zone_z0 华东, Zone_z1 华北, Zone_z2 华南, Zone_na0 北美
			bucket: 'disk-server',
			baseUrl: 'http://rhkudvgpl.hd-bkt.clouddn.com/' // 用于拼接已上传文件的完整地址
		}
	};

	// 上传格式和大小限制
	config.multipart = {
		// fileSize: '50mb',
		fileSize: 1048576000,
		// mode: 'stream',
		mode: 'file',
		fileExtensions: [
			// images
			'.jpg',
			'.jpeg', // image/jpeg
			'.png', // image/png, image/x-png
			'.gif', // image/gif
			'.bmp', // image/bmp
			'.wbmp', // image/vnd.wap.wbmp
			'.webp',
			'.tif',
			'.psd',
			// text
			'.svg',
			'.js',
			'.jsx',
			'.json',
			'.css',
			'.less',
			'.html',
			'.htm',
			'.xml',
			'txt',
			// tar
			'.zip',
			'.gz',
			'.tgz',
			'.gzip',
			// video
			'.mp3',
			'.mp4',
			'.avi'
		]
	};
	return {
		...config,
		...userConfig
	};
};
